package cn.company.database;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

/**
 * 读取数据库驱动相关信息的类
 * @author mzba
 *
 */
public class FileUtils {
	
	private Properties properties;
	
	public FileUtils(){
		properties = new Properties();
	}
	
	public Properties getDbInfo(){
		String path = getClass().getProtectionDomain().getCodeSource().getLocation().toString();
	    path = path.substring(6, path.length());

	    if (path.indexOf("WEB-INF") > 0) {
	      path = path.substring(0, path.indexOf("/WEB-INF") + 9);
	    }
	    else{
	      path = "d:";
	    }
	    try {
	      this.properties.load(new FileReader(path + "lib/db.pro"));
	    }
	    catch (FileNotFoundException e) {
	      e.printStackTrace();
	    }
	    catch (IOException e) {
	      e.printStackTrace();
	    }
		return properties;
	}
}
